package com.gitee.shoes.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gitee.shoes.dao.ProductBaseMapper;
import com.gitee.shoes.entity.ProductBase;
import com.gitee.shoes.enumeration.PlatformEnum;
import com.gitee.shoes.service.IProductBaseService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.*;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author LYH
 * @since 2020-12-09
 */
@Service
@RequiredArgsConstructor
public class ProductBaseServiceImpl extends ServiceImpl<ProductBaseMapper, ProductBase> implements IProductBaseService {


    @Override
    public ProductBase getOneByPlatformAndPlatformIdAndStyleId(PlatformEnum platform, String platformId, String styleId) {
        LambdaQueryWrapper<ProductBase> qw = Wrappers.<ProductBase>lambdaQuery().eq(ProductBase::getPlatform, platform)
                .eq(ProductBase::getPlatformId, platformId);
        if (styleId == null) {
            qw.isNull(ProductBase::getStyleId);
        } else {
            qw.eq(ProductBase::getStyleId, styleId);
        }
        return getOne(qw);
    }

    @Override
    public List<ProductBase> findAllByArticle(String article) {
        return list(Wrappers.<ProductBase>lambdaQuery().eq(ProductBase::getArticle, article));
    }
}
